package com.codexsoft.test;

import com.codexsoft.test.entities.User;
import com.codexsoft.test.jpamodel.EMF;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import javax.persistence.EntityManager;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 26.08.11
 * Time: 10:57
 * To change this template use File | Settings | File Templates.
 */
public class LoggedUsersPage extends WebPage {
    public LoggedUsersPage(){
        EntityManager em = EMF.get().createEntityManager();
        String query = "SELECT FROM " + User.class.getName();
        List<User> userList = em.createQuery(query).getResultList();
        PageableListView users = new PageableListView("users",userList,2){
            @Override
        protected void populateItem(ListItem item){
                User user = (User)item.getModelObject();
                item.add(new Label("name",user.getName()));
                item.add(new Label("surname",user.getSurname()));
                item.add(new Label("nickname",user.getNickname()));
                item.add(new Label("country",user.getCountry()));
                item.add(new Label("city",user.getCity()));
                item.add(new Label("university",user.getUniversity()));
                item.add(new Label("faculty",user.getFaculty()));
                item.add(new Label("speciality",user.getSpeciality()));
                item.add(new Label("email",user.getEmail()));
                item.add(new Label("additionalInformation",user.getAdditionalInformation()));
            }
        };
        add(users);
        add(new PagingNavigator("navigator",users));
        add(new BookmarkablePageLink("link",UInfoPage.class));
    }
}
